<?php
/**
 * Describe plugin here
 */

elgg_register_event_handler('init', 'system', 'hello_world_init');

function hello_world_init() {

	// Register plugin to Elgg routing
	elgg_register_page_handler('hello', 'hello_page_handler');
	
	// Register Elgg Meniu
	$item = new ElggMenuItem('hello', 'Hello', 'hello/world');
	elgg_register_menu_item('site', $item);
	
	// Register sidebar menu
	elgg_register_menu_item('page', array(
		'name' => 'world',
		'text' => 'Hello world',
		'href' => 'hello/world',
		'contexts' => array('hello'),
	));
	elgg_register_menu_item('page', array(
		'name' => 'dolly',
		'text' => 'Hello dolly',
		'href' => 'hello/dolly',
		'contexts' => array('hello'),
	));
}

function hello_page_handler($page, $identifier) {
	
	$plugin_path = elgg_get_plugins_path();
	$base_path = $plugin_path . 'helloworld/pages';
	
	switch($page[0]){
		case 'world':
			require "$base_path/world.php";
			break;
		case 'dolly':
			require "$base_path/dolly.php";
			break;
		default:
			echo "request for $identifier $page[0]";
			break;
	}
	// return true to let Elgg know that a page was sent to browser
	return true;
}
